﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DriverLicence.Cnsl
{
    public class ConfigurationManager
    {

        public static string Get(AppSettingsKey key)
        {
            return Congifurations.GetInstance()[key];
        }

        public enum AppSettingsKey
        {
            StartingMonthColumn,
            CategoryHeadingColumn
        }

        private class Congifurations
        {
            private Congifurations()
            {
                this._cachedConfigurations = new Dictionary<int, string>();
            }

            private static Congifurations _instance;

            private Dictionary<int, string> _cachedConfigurations;

            public static Congifurations GetInstance()
            {
                if (_instance == null)
                {
                    _instance = new Congifurations();
                }
                return _instance;
            }

            public string this[AppSettingsKey key]
            {
                get
                {
                    int intKey = (int)key;
                    if (!_cachedConfigurations.ContainsKey(intKey))
                    {
                        _cachedConfigurations.Add(intKey, ConfigurationSettings.AppSettings[key.ToString()]);
                    }
                    return _cachedConfigurations[intKey];
                }
            }

        }
    }
}
